// control check

// getTextboxValue
function getTextboxValue(objId) {
    var obj = jQuery("#" + objId);
    
    return obj.val();
}

// setTextboxValue
function setTextboxValue(objId, value) {
    var obj = jQuery("#" + objId);
    
    obj.val(value);
}

function getChecked(objId){
    var obj = jQuery("#"+objId);
    return obj.attr("checked");
}
//getCheckboxValue
function getCheckboxValue(objName) {
    var arrCheckBoxVal = new Array();
    var j=0;
    var arrCheck = document.getElementsByName(objName);
    var str="";
    for(var i = 0; i < arrCheck.length; i++){
        if(arrCheck[i].checked){
            arrCheckBoxVal[j] = arrCheck[i].value;
            j++;
        }
    }
    if (j==0) {
        return "";
    } else {
        return arrayToJson(arrCheckBoxVal);
    }
}
//TODO 
function getRadioValue(objName) {
    var arrRadio = document.getElementsByName(objName);
    for(var i = 0; i < arrRadio.length; i++){
        if(arrRadio[i].checked){
            return arrRadio[i].value;
        }
    }
    return "";
    /*var valradio = $('input[name='+objId+'][checked]').val();
    return valradio;*/
 }

function getRadioText(objName) {
    var txtRadioText = "";
    jQuery("input[name=" + objName + "]").each(function(){
        if (jQuery(this).attr("checked") == true){
            txtRadioText = jQuery(this).parent().text();
        } else {}
    });
    return txtRadioText;
}

function getCheckBoxText(objName) {
    var arrCheckBoxText = new Array();
    var intCount = 0;
    jQuery("input[name=" + objName + "]").each(function(){
        if (jQuery(this).attr("checked") == true){
            arrCheckBoxText[intCount] = jQuery(this).parent().text();
            intCount = intCount + 1;
        } else {}
    });

    if (intCount==0) {
        return "";
    } else {
        return arrayToJson(arrCheckBoxText);
    }
}
// setCheckboxOn
function setChecked(objId,flag) {
    var obj = jQuery("#" + objId);
    obj.attr("checked", flag);
}

//setCheckedByValue
function setCheckBoxByValue(strName, arrValue) {
    if (arrValue != null) {
        for (i=0; i<arrValue.length; i++){
            objAttr("input[type='checkbox'][name='"+ strName + "'][value='"+ arrValue[i] + "']", "checked", "checked");
        }
    } else {
        objAttr("input[type='checkbox'][name='"+ strName + "']", "checked", "");
    }
}

//setCheckedByValue
function setRadioByValue(strName, strValue) {
    objAttr("input[type='radio'][name='"+ strName + "'][value='"+ strValue + "']", "checked", "checked");
}

// zen -> han
function zenToHanC(objId) {
    var value = jQuery("#" + objId).val();

    jQuery("#" + objId).val(zenToHan(value));
}

// zeroShift
function zeroShiftC(objId) {
    var value = jQuery("#" + objId).val();

    jQuery("#" + objId).val(zeroShift(value));
}

// zeroFormat
function zeroFormatC(objId,number) {
    var value = jQuery("#" + objId).val();

    jQuery("#" + objId).val(zeroFormat(value,number));
}

//searchTrim
function searchTrim(objId) {
    trim(objId);
}

//updateTrim
function updateTrim(objId) {
    trim(objId);
}

//tosearchTrim
function toSearchTrim(value) {
    return toTrim(value);
}

//toupdateTrim
function toUpdateTrim(value) {
    return toTrim(value);
}


// trim
function trim(objId) {
    var value = jQuery("#" + objId).val();

    jQuery("#" + objId).val(toTrim(value));
}

// ltrim
function ltrim(objId) {
    var value = jQuery("#" + objId).val();

    jQuery("#" + objId).val(toLTrim(value));
}

// rtrim
function rtrim(objId) {
    var value = jQuery("#" + objId).val();

    jQuery("#" + objId).val(toRTrim(value));
}

// selected value in dropdownList
function getSelectedValue(objId) {
    return jQuery("#" + objId + " option:selected").val();
}

// selected text in dropdownList
function getSelectedText(objId) {
    return jQuery("#" + objId + " option:selected").text();
}

// set selected in dropdownList
function setSelectedByValue(objId, value) {
    jQuery("#" + objId).attr("value",value);
}

// clear dropdownList
function clearList(objId) {
    jQuery("#" + objId).empty();
}

// remove from dropdownList at value
function removeFromDropdownList(objId, value) {
    jQuery("#" + objId + " option").each(function() {
        if(jQuery(this).val() == value) {
            jQuery(this).remove();
        }
    });
}

// add in dropdownList at index
function addToList(objId,value,text) {
    jQuery("<option value=" + value + ">" + text + "</option>").appendTo(jQuery("#" + objId));
}

// format date(yyyyMMdd -> yyyy-MM-dd,yyyy/MM/dd)
function dateFormat(objId, formatString) {
    var returnValue;
    var value = jQuery("#" + objId).val();

    if(chkDate(objId)) {
        if(formatString == "yyyy-MM-dd") {
            returnValue = value.substr(0,4) + "-" + value.substr(4,2) + "-" + value.substr(6,2);
        }else if(formatString == "yyyy/MM/dd") {
            returnValue = value.substr(0,4) + "/" + value.substr(4,2) + "/" + value.substr(6,2);
        }else {
            returnValue = value;
        }
    }
    
    jQuery("#" + objId).val(returnValue);
}

// string check

// zen -> han
function zenToHan(value) {
    var result = "";
    for (i=0 ; i<value.length; i++){
        code = value.charCodeAt(i);
        if(code >= 65281 && code <= 65373) {
            result += String.fromCharCode(value.charCodeAt(i) - 65248);
        }else if (code == 12288) {
            result += String.fromCharCode(value.charCodeAt(i) - 12288 + 32);
        }else {
            result += value.charAt(i);
        }
    }
    return result;
}

// zeroShift
function zeroShift(value) {
    var rep = new RegExp("^0+0?");
    
    return value.replace(rep,"");
}

// zeroFormat
function zeroFormat(value, zeroNumber) {
    var temp = value;
    
    while(temp.length < zeroNumber) {
        temp="0" + temp;
    }
    return temp;
}

// string trim
function toTrim(value) {
    var start = 0;
    var end = value.length - 1;
    
    while(value.charCodeAt(start) == 12288 || value.charAt(start) == " ") start++;
    while(value.charCodeAt(end) == 12288 || value.charAt(end) == " ") end--;
    
    return value.substr(start, end - start + 1);
}

// string left trim
function toLTrim(value) {
    var start = 0;
    var end = value.length - 1;
    
    while(value.charCodeAt(start) == 12288 || value.charAt(start) == " ") start++;
    
    return value.substr(start, end - start + 1);
}

// string right trim
function toRTrim(value) {
    var start = 0;
    var end = value.length - 1;
    
    while(value.charCodeAt(end) == 12288 || value.charAt(end) == " ") end--;
    
    return value.substr(start, end - start + 1);
}

// length of char
function getLength(value) {
    var length=value.length;
    return length;
}

// length of byte
function getBLength(value) {
    var length=value.replace(/[^\x00-\xFF]/g,'**').length;
    return length;
}

//get value
function getValue(objId)
{
    var value=jQuery("#" + objId).attr("value");
    return value;
}

//set value
function setValue(objId,value)
{
    jQuery("#" + objId).attr("value",value);
}

//get selected index
function getSelectedIndex(objId)
{
      var index=jQuery("#" + objId).get(0).selectedIndex;
      return index;
}

//get Selected By Index
function setSelectedByIndex(objId,index)
{
    jQuery("#" + objId).get(0).selectedIndex=index;
}

//getDisabled
function getDisabled(objId)
{
    var obj=jQuery("#" + objId);
    return obj.attr("Disabled");
}

//setDisabled
function setDisabled(objId,flag)
{
    var obj=jQuery("#" + objId);
    obj.attr("disabled",flag);
}

//getReadOnly
function getReadOnly(objId)
{
    var obj=jQuery("#" + objId);
    return obj.attr("readonly");
}

//setReadOnly
function setReadOnly(objId,flag)
{
    var obj=jQuery("#" + objId);
    obj.attr("readonly",flag);
}

//setInnerText
function setInnerText(objId,value)
{
    var obj=jQuery("#" + objId);
    obj.text(value);
}

//getInnertText
function getInnerText(objId)
{
    var obj=jQuery("#" + objId);
    return obj.text();
}

//setInnerHTML
function setInnerHTML(objId,value)
{
    var obj=jQuery("#" + objId);
    var childObj = obj;
    childObj.find("*").each(function(){
        if(jQuery(this).attr("id") != ""){
            jQuery(this).removeAttr("onclick");
            jQuery(this).unbind();
        }
    });
    obj.html(value);
}

//getInnerHTML
function getInnerHTML(objId)
{
    var obj=jQuery("#" + objId);
    return obj.html();
}

//setFocus
function setFocus(objId)
{
    var obj=jQuery("#" + objId);
    obj.focus();
}

//setSelect
function setSelect(objId)
{
    var obj=jQuery("#" + objId);
    obj.select();

}

//showDialog
function showDialog(url, _left, _top, _width, _height, _modal, _resizable, _status, _scroll) {
    var result;
    var iTop = (window.screen.availHeight- 30 - _height) / 2;
    var iLeft = (window.screen.availWidth- 10 - _width) / 2;

    if(_left == -1 || _top == -1) {
        _left = iLeft;
        _top = iTop;
    }

    var ieFeatures = "dialogWidth=" + _width + "px;" +
        "dialogHeight=" + _height + "px;" +
        "dialogLeft=" + _left + "px;" +
        "dialogTop=" + _top + "px;" +
        "resizable=" + _resizable + ";" +
        "status=" + _status + ";" +
        "scroll=" + _scroll;
    var otherFeatures = "width=" + _width + "," +
        "height=" +  _height + "," +
        "left=" + _left + "," +
        "top=" + _top + "," +
        "resizable=" + _resizable + "," +
        "status=" + _status + "," +
        "scrollable=" + _scroll;

    if(_modal == 'yes') {
        window.openSonModel = true;
    } else {
        window.openSonModel = false;
    }

    if(navigator.userAgent.toLowerCase().indexOf("ie") != -1) {  //ie
        if(_modal == 'yes') {
            result = window.showModalDialog(url, window, ieFeatures);
        } else {
            result = window.showModelessDialog(url, window, ieFeatures);
        }
    } else { //other
        if(_modal == 'yes') {
            result = window.showModalDialog(url, window, ieFeatures);
        } else {
            otherFeatures += ',modal=' +  _modal;
            result = window.open(url, '_blank', otherFeatures);
            windowArray.push(result);
        }
    }

    return result;
}

//getHost
function getHost(){
    return document.getElementById("host").value;
}

//PictureHost
function getPictureHost(){
    return document.getElementById("pictureHost").value;
}

//theme
function getTheme(){
    return document.getElementById("theme").value;
}

//getMessage
function getMessage(messageId){
    //return eval("document.forms['messages']." + messageId + ".value");
      return document.getElementById(messageId).value;
}

function getLabel(labelId){
    //return eval("document.forms['messages']." + messageId + ".value");
    return document.getElementById(labelId).value;
}

//getLocalLanguage
function getLocalLanguage(){
    return document.getElementById("localLanguage").value;
}

//setErrorMsg
function setErrorMsg(arrMsg, divWidth) {
    if(arguments.length == 2){
        clearErrorMsg();
    }else if(arguments.length == 3){
        clearErrorMsg(arguments[2]);
    }

    if(arrMsg == null) {
        return;
    }
    if(divWidth == ""){
        divWidth = 600;
    }
    if(arguments.length == 2){
        if(arrMsg.length > 0) {
            for(i = 0; i < arrMsg.length; i++) {
                liNode = jQuery(document.createElement("li"));
                liNode.text(arrMsg[i]);
                liNode.css({"color":"#FF0000"});
                liNode.appendTo("#errorList");
            }
        } else if(arrMsg.msg) {
            for(i = 0; i < arrMsg.msg.length; i++) {
                liNode = jQuery(document.createElement("li"));
                liNode.text(arrMsg.msg[i]);
                liNode.css({"color":"#FF0000"});
                liNode.appendTo("#errorList");
            }
        } else {
            return;
        }
        if(divWidth){
            jQuery("#errorPop").css("width", divWidth);
        }
        jQuery("#errorPop").focus();
    }else if(arguments.length == 3){
        objUl = jQuery(document.createElement("ul"));
        objUl.attr("id","errorMessageInfo");
        if(arrMsg.length > 0) {
            for(i = 0; i < arrMsg.length; i++) {
                liNode = jQuery(document.createElement("li"));
                liNode.text(arrMsg[i]);
                liNode.css({"color":"#FF0000"});
                liNode.appendTo(objUl);
            }
        } else if(arrMsg.msg) {
            for(i = 0; i < arrMsg.msg.length; i++) {
                liNode = jQuery(document.createElement("li"));
                liNode.text(arrMsg.msg[i]);
                liNode.css({"color":"#FF0000"});
                liNode.appendTo(objUl);
            }
        } else {
            return;
        }
        jQuery(objUl).prependTo("#" + arguments[2]);
        jQuery("#" + arguments[2]).focus();
    }
}

//clearErrorMsg
function clearErrorMsg() {
    if(arguments.length == 0){
        jQuery("#errorList li").remove();
    }
    if(arguments.length == 1){
        jQuery("#" + arguments[0]+" ul[id='errorMessageInfo']").remove();
    }
}

//pageCreat
function pageCreat(curPage, recordCount, pageContainerId) {
    var pageContainer = getPageContainer(pageContainerId);
    var orderContainerId = null;
    if(arguments.length <=3){
        var obj = document.getElementsByName("pager_orderColumn");
        if (obj.length > 1){
            orderContainerId = pageContainerId.replace("pageHead","orderHead");
            orderContainerId = orderContainerId.replace("pageFoot","orderHead");
        } else {
            orderContainerId = "orderDiv";
        }
    }else{
        orderContainerId = arguments[3];
    }
    var pageSize = getPageSize(pageContainerId);
    if(curPage != null && recordCount != null && pageSize != null) {
        var totalPage = parseInt(recordCount / pageSize);

        if(recordCount % pageSize) {
            totalPage = totalPage + 1;
        }

        if(curPage > totalPage) {
            curPage = totalPage;
        }

        var fromRecord = (curPage - 1) * pageSize + 1;
        if(fromRecord < 0){
            fromRecord = 0;
        }
        
        var toRecord = curPage * pageSize;
        
        if (toRecord > recordCount) {
            toRecord = recordCount;
        }

        if(curPage == 0 || recordCount == 0){
            jQuery("#curPage", pageContainer).val("0");
            jQuery("#totalPage", pageContainer).text("0");
            jQuery("#fromRecord", pageContainer).text("0");
            jQuery("#toRecord", pageContainer).text("0");
            jQuery("#recordCount", pageContainer).text("0");
        }else{
            jQuery("#curPage", pageContainer).val(curPage.toString());
            jQuery("#totalPage", pageContainer).text(totalPage.toString());
            jQuery("#fromRecord", pageContainer).text(fromRecord.toString());
            jQuery("#toRecord", pageContainer).text(toRecord.toString());
            jQuery("#recordCount", pageContainer).text(recordCount.toString());
        }
        jQuery("#curPageHid", pageContainer).val(jQuery("#curPage", pageContainer).val());
    }
    else {
        return;
    }

    if(jQuery("#pagerDiv", pageContainer).attr("flag") == null) {
        jQuery("#pagerDiv", pageContainer).attr("flag", "1");

        //curPage
        jQuery("#curPage", pageContainer).removeAttr("onblur");
        jQuery("#curPage", pageContainer).blur(function(e){
            e.preventDefault();
            if(jQuery("#curPage", pageContainer).val() == jQuery("#curPageHid", pageContainer).val()){
                return;
            }
            var numPattern = /^\d*$/;
            result = numPattern.test(jQuery("#curPage", pageContainer).val());
            if(!result){
                jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
                return;
            }
            var curPageText = "";
            var curPageNo;
            for(i = 0; i < jQuery("#curPage", pageContainer).val().length; i++) {
                if( curPageText == "" && jQuery("#curPage", pageContainer).val().substring(i, i + 1) == 0){
                }else{
                    curPageText = curPageText + jQuery("#curPage", pageContainer).val().substring(i, i + 1);
                }
            }
            if(curPageText.length > 0) {
                curPageNo = parseInt(curPageText);
            }else{
                jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
                return;
            }
            if( curPageNo < 1 ||
                curPageNo > parseInt(jQuery("#totalPage", pageContainer).text())) {
                jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
                return;
            }
            jQuery("#curPageHid", pageContainer).val(curPageText);
            gotoPage(pageContainerId, orderContainerId);
        });

        //firstPage
        jQuery("#firstPage", pageContainer).removeAttr("onclick");
        jQuery("#firstPage", pageContainer).click(function(e){
            e.preventDefault();
            if(parseInt(jQuery("#curPage", pageContainer).val()) <= 1) {
                return;
            }
            jQuery("#curPageHid", pageContainer).val("1");
            firstPage(pageContainerId, orderContainerId);
        });

        //prePage
        jQuery("#prePage", pageContainer).removeAttr("onclick");
        jQuery("#prePage", pageContainer).click(function(e){
            e.preventDefault();
            var numPattern = /^\d*$/;
            result = numPattern.test(jQuery("#curPage", pageContainer).val());
            if(!result){
                jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
                return;
            }
            if(parseInt(jQuery("#curPage", pageContainer).val()) <= 1) {
                return;
            }
            jQuery("#curPageHid", pageContainer).val((parseInt(jQuery("#curPage", pageContainer).val()) - 1).toString());
            prePage(pageContainerId, orderContainerId);
        });

        //nextPage
        jQuery("#nextPage", pageContainer).removeAttr("onclick");
        jQuery("#nextPage", pageContainer).click(function(e){
            e.preventDefault();
            var numPattern = /^\d*$/;
            result = numPattern.test(jQuery("#curPage", pageContainer).val());
            if(!result){
                jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
                return;
            }
            if(parseInt(jQuery("#curPage", pageContainer).val()) >= parseInt(jQuery("#totalPage", pageContainer).text())) {
                return;
            }
            jQuery("#curPageHid", pageContainer).val((parseInt(jQuery("#curPage", pageContainer).val()) + 1).toString());
            nextPage(pageContainerId, orderContainerId);
        });

        //lastPage
        jQuery("#lastPage", pageContainer).removeAttr("onclick");
        jQuery("#lastPage", pageContainer).click(function(e){
            e.preventDefault();
            if(parseInt(jQuery("#curPage", pageContainer).val()) >= parseInt(jQuery("#totalPage", pageContainer).text())) {
                return;
            }
            jQuery("#curPageHid", pageContainer).val(parseInt(jQuery("#totalPage", pageContainer).text()).toString());
            lastPage(pageContainerId, orderContainerId);
        });

        //other explorer:firefox etc
        if( navigator.userAgent.toLowerCase().indexOf("firefox") >= 0 ||
            navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ||
            navigator.userAgent.toLowerCase().indexOf("opera") >= 0){
            var evt = SearchEvent();
            if(evt.target.id == "curPage"){
                jQuery("#" + evt.target.id, pageContainer).blur();
            }else{
                jQuery("#" + evt.target.id, pageContainer).click();
            }
        }
    }
}

//getPageContainer
function getPageContainer(pageContainerId){
    var pageContainer;
    if(pageContainerId){
        pageContainer = jQuery("#" + pageContainerId);
    }else{
        pageContainer = jQuery(document);
    }

    return pageContainer;
}

//initPager
function initPager(){
    var pageContainerId = null;
    if( navigator.userAgent.toLowerCase().indexOf("firefox") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("opera") >= 0){
        var evt = SearchEvent();
        pageContainerId = jQuery(evt.target).parent().parent().attr("id"); 
    }else{
        pageContainerId = jQuery(window.event.srcElement).parent().parent().attr("id");
    }

    pageCreat(getCurPage(pageContainerId), getDataCount(pageContainerId), pageContainerId);
}

function gotoPageNo(pageNo){
    var pageContainerId = null;
    if( navigator.userAgent.toLowerCase().indexOf("firefox") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("opera") >= 0){
        var evt = SearchEvent();
        pageContainerId = jQuery(evt.target).parent().parent().parent().attr("id"); 
    }else{
        pageContainerId = jQuery(window.event.srcElement).parent().parent().parent().attr("id");
    }
    var pageContainer = getPageContainer(pageContainerId);
    jQuery("#curPageHid", pageContainer).val(pageNo);
    if(pageContainerId){
        orderContainerId = "order" + pageContainerId.replace("page","");
    }
    gotoPage(pageContainerId, orderContainerId);
}

//initPager
function initPagerBlur(){
    var pageContainerId = null;
    if( navigator.userAgent.toLowerCase().indexOf("firefox") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("opera") >= 0){
        var evt = SearchEvent();
        pageContainerId = jQuery(evt.target).parent().parent().attr("id"); 
    }else{
        pageContainerId = jQuery(window.event.srcElement).parent().parent().attr("id");
    }
    var pageContainer = getPageContainer(pageContainerId);
    if(jQuery("#curPage", pageContainer).val() == jQuery("#curPageHid", pageContainer).val()){
        return;
    }
    var numPattern = /^\d*$/;
    result = numPattern.test(jQuery("#curPage", pageContainer).val());
    if(!result){
        jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
        return;
    }
    var curPageText = "";
    var curPageNo;
    for(i = 0; i < jQuery("#curPage", pageContainer).val().length; i++) {
        if( curPageText == "" && jQuery("#curPage", pageContainer).val().substring(i, i + 1) == 0){
        }else{
            curPageText = curPageText + jQuery("#curPage", pageContainer).val().substring(i, i + 1);
        }
    }
    if(curPageText.length > 0) {
        curPageNo = parseInt(curPageText);
    }else{
        jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
        return;
    }
    if( curPageNo < 1 ||
        curPageNo > parseInt(jQuery("#totalPage", pageContainer).text())) {
        jQuery("#curPage", pageContainer).val(jQuery("#curPageHid", pageContainer).val());
        return;
    }
    jQuery("#curPageHid", pageContainer).val(curPageText);
    var orderContainerId = null;
    if(pageContainerId){
        orderContainerId = "order" + pageContainerId.replace("page","");
    }
    gotoPage(pageContainerId, orderContainerId);
}

function pageSizeChange(){
    var pageContainerId = null;
    if( navigator.userAgent.toLowerCase().indexOf("firefox") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("opera") >= 0){
        var evt = SearchEvent();
        pageContainerId = jQuery(evt.target).parent().parent().attr("id"); 
    }else{
        pageContainerId = jQuery(window.event.srcElement).parent().parent().attr("id");
    }
    var orderContainerId = null;
    if(pageContainerId){
        orderContainerId = "order" + pageContainerId.replace("page","");
        orderContainerId = orderContainerId.replace("Foot","Head");
    }
    tempContainerId = pageContainerId;
    var pageSize = getPageSize(pageContainerId);
    if(pageContainerId.indexOf("pageFoot")>=0){
        pageContainer = getPageContainer(tempContainerId.replace("pageFoot", "pageHead"));
        jQuery("#pageSizeSelect", pageContainer).val(pageSize);
    }
    if(pageContainerId.indexOf("pageHead")>=0){
        pageContainer = getPageContainer(tempContainerId.replace("pageHead", "pageFoot"));
        jQuery("#pageSizeSelect", pageContainer).val(pageSize);;
    }
    sizeChangeSearch(pageContainerId, orderContainerId);
}
//getDataCount
function getDataCount(pageContainerId){
    var pageContainer = getPageContainer(pageContainerId);
    var dataCount;
    if(jQuery("#dataCount", pageContainer) != null && jQuery("#dataCount", pageContainer).val() != "") {
        dataCount = parseInt(jQuery("#dataCount", pageContainer).val());
    }
    return dataCount;
}

//getCurPage
function getCurPage(pageContainerId){
    var pageContainer = getPageContainer(pageContainerId);
    var curPage;
    if(jQuery("#curPageHid", pageContainer) != null && jQuery("#curPageHid", pageContainer).val() != "") {
        curPage = parseInt(jQuery("#curPageHid", pageContainer).val());
    }
    return curPage;
}

//getPageSize
function getPageSize(pageContainerId){
    var pageContainer = getPageContainer(pageContainerId);
    var pageSize;
    pageSize = jQuery("#pageSizeSelect option:selected", pageContainer).val();
    return pageSize;
}

//getOrderColumn
function getOrderColumn(orderContainerId){
    var orderContainer = getOrderContainer(orderContainerId);
    var orderColumn="";
    if(jQuery("#pager_orderColumn", orderContainer) != null && jQuery("#pager_orderColumn", orderContainer).val() != "") {
        orderColumn = jQuery("#pager_orderColumn", orderContainer).val();
    }
    return orderColumn;
}

//getOrder
function getOrder(orderContainerId){
    var orderContainer = getOrderContainer(orderContainerId);
    var order="";
    if(jQuery("#pager_order", orderContainer) != null && jQuery("#pager_order", orderContainer).val() != ""){
        order = jQuery("#pager_order", orderContainer).val();
    }
    return order;
}

//initOrder
function initOrder(orderContainerId){
    var orderContainerId = orderContainerId;
    if( navigator.userAgent.toLowerCase().indexOf("firefox") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ||
        navigator.userAgent.toLowerCase().indexOf("opera") >= 0){
        var evt = SearchEvent();
        if( jQuery(evt.target).attr("id") == "ascendon" ||
            jQuery(evt.target).attr("id") == "ascendoff" ||
            jQuery(evt.target).attr("id") == "descendon" ||
            jQuery(evt.target).attr("id") == "descendoff"){
            orderContainerId = jQuery(evt.target).parent().parent().parent().parent().parent().attr("id");
        }
    }else{
        if( jQuery(window.event.srcElement).attr("id") == "ascendon" ||
            jQuery(window.event.srcElement).attr("id") == "ascendoff" ||
            jQuery(window.event.srcElement).attr("id") == "descendon" ||
            jQuery(window.event.srcElement).attr("id") == "descendoff"){
            orderContainerId = jQuery(window.event.srcElement).parent().parent().parent().parent().parent().attr("id");
        }
    }
    setOrderColumn(orderContainerId);
}

//setSearchOrder
function setSearchOrder(orderContainerId){
    if(orderContainerId == ""){
        orderContainerId = null;
    }
    var orderContainer = getOrderContainer(orderContainerId);
    var trHeader = "#trHeader";
    if(orderContainerId){
        trHeader = trHeader + "_" + orderContainerId;
    }
    if(jQuery("#pager_order", orderContainer) != null){
        jQuery("#pager_order", orderContainer).val("");
    }
    if(jQuery("#pager_orderColumn", orderContainer) != null) {
        jQuery("#pager_orderColumn", orderContainer).val("");
    }
    jQuery(trHeader).find("td[id]").each(function(){
        jQuery(this).css("backgroundColor", jQuery(this).attr("preColor"));
        jQuery(this).attr("flag", "0");
        jQuery(this).find("#asconView").css("display", "none");
        jQuery(this).find("#desconView").css("display", "none");
    });
    jQuery("#ascendon", orderContainer).css("display", "none");
    jQuery("#ascendoff", orderContainer).css("display", "none");
    jQuery("#descendon", orderContainer).css("display", "none");
    jQuery("#descendoff", orderContainer).css("display", "none");
}

//getPageContainer
function getOrderContainer(orderContainerId){
    var orderContainer;
    if(orderContainerId){
        orderContainer = jQuery("#" + orderContainerId);
    }else{
        orderContainer = jQuery(document);
    }

    return orderContainer;
}

//setOrderColumn
function setOrderColumn(orderContainerId) {
    if(orderContainerId == ""){
        orderContainerId = null;
    }
    var orderContainer = getOrderContainer(orderContainerId);
    var trHeader = "#trHeader";
    var pageContainerId = null;
    if(orderContainerId){
        trHeader = trHeader + "_" + orderContainerId;
        var obj = document.getElementsByName("pager_orderColumn");
        if (obj.length > 1){
            pageContainerId = orderContainerId.replace("orderHead","pageHead");
        } else {
            pageContainerId = "page" + orderContainerId.replace("order","");
        }
    }
    var pageContainer = getPageContainer(pageContainerId);

    jQuery("#ascendon", orderContainer).removeAttr("onclick");
    jQuery("#ascendoff", orderContainer).removeAttr("onclick");
    jQuery("#descendon", orderContainer).removeAttr("onclick");
    jQuery("#descendoff", orderContainer).removeAttr("onclick");
    jQuery(trHeader).find("td[id]").each(function(){
        jQuery(this).removeAttr("onclick");
    });

    var clickColor = jQuery("#clickColor", orderContainer).val();

/*    jQuery("#ascendoff, #ascendon", orderContainer).click(function(){
        var orderColumn;
        var order;
        jQuery(trHeader).find("td[id]").each(function(){
            if(jQuery(this).attr("flag") == "1"){
                orderColumn = jQuery(this).attr("id"); 
                jQuery(this).find("#asconView").css("display", "inline");
                jQuery(this).find("#desconView").css("display", "none");
            }
        });
        if(orderColumn != null){
            jQuery("#ascendon", orderContainer).css("display", "inline");
            jQuery("#ascendoff", orderContainer).css("display", "none");
            jQuery("#descendon", orderContainer).css("display", "none");
            jQuery("#descendoff", orderContainer).css("display", "inline");
            order = "asc";
            if(jQuery("#pager_order", orderContainer) != null){
                jQuery("#pager_order", orderContainer).val(order);
            }
            if(jQuery("#pager_orderColumn", orderContainer) != null) {
                jQuery("#pager_orderColumn", orderContainer).val(orderColumn);
            }
            if(jQuery("#curPageHid", pageContainer) != null) {
                jQuery("#curPageHid", pageContainer).val("1");
            }
            orderSearch(pageContainerId, orderContainerId);
        }
    });
    jQuery("#descendoff, #descendon", orderContainer).click(function(){
        var orderColumn;
        var order;
        jQuery(trHeader).find("td[id]").each(function(){
            if(jQuery(this).attr("flag") == "1"){
                orderColumn = jQuery(this).attr("id"); 
                jQuery(this).find("#asconView").css("display", "none");
                jQuery(this).find("#desconView").css("display", "inline");
            }
        });
        if(orderColumn != null){
            jQuery("#ascendon", orderContainer).css("display", "none");
            jQuery("#ascendoff", orderContainer).css("display", "inline");
            jQuery("#descendon", orderContainer).css("display", "inline");
            jQuery("#descendoff", orderContainer).css("display", "none");
            order = "desc";
            if(jQuery("#pager_order", orderContainer) != null){
                jQuery("#pager_order", orderContainer).val(order);
            }
            if(jQuery("#pager_orderColumn", orderContainer) != null) {
                jQuery("#pager_orderColumn", orderContainer).val(orderColumn);
            }
            if(jQuery("#curPageHid", pageContainer) != null) {
                jQuery("#curPageHid", pageContainer).val("1");
            }
            orderSearch(pageContainerId, orderContainerId);
        }
    });
*/
    jQuery(trHeader).find("td[id]").each(function(){
        
        var order;
        var orderColumn;
        if(jQuery(this).attr("preColor") == null){
            jQuery(this).attr("preColor", jQuery(this).css("backgroundColor"));
        }
        if(jQuery(this).attr("id") == jQuery("#pager_orderColumn").val()){
            jQuery(this).css("backgroundColor", clickColor);
            jQuery(this).attr("flag", "1");
        }

        jQuery(trHeader).find("td[id='" + jQuery(this).attr("id") + "']").live(
            "click", function(){
            if(jQuery(this).attr("flag") == "1"){
                if(jQuery("#ascendon", orderContainer).css("display") == "inline"){
                    order = "desc";
                }else{
                    order = "asc";
                }
            }else{
                order = "asc";
            }

            jQuery(trHeader).find("td[id]").each(function(){
                jQuery(this).css("backgroundColor", jQuery(this).attr("preColor"));
                jQuery(this).attr("flag", "0");
                jQuery(this).find("#asconView").css("display", "none");
                jQuery(this).find("#desconView").css("display", "none");
            });

            if(order == "asc"){
                jQuery(this).find("#asconView").css("display", "inline");
                jQuery(this).find("#desconView").css("display", "none");
                jQuery("#ascendon", orderContainer).css("display", "inline");
                jQuery("#ascendoff", orderContainer).css("display", "none");
                jQuery("#descendon", orderContainer).css("display", "none");
                jQuery("#descendoff", orderContainer).css("display", "inline");
            }else{
                jQuery(this).find("#asconView").css("display", "none");
                jQuery(this).find("#desconView").css("display", "inline");
                jQuery("#ascendon", orderContainer).css("display", "none");
                jQuery("#ascendoff", orderContainer).css("display", "inline");
                jQuery("#descendon", orderContainer).css("display", "inline");
                jQuery("#descendoff", orderContainer).css("display", "none");
            }
            jQuery(this).css("backgroundColor", clickColor);
            jQuery(this).attr("flag", "1");

            if(jQuery("#pager_order", orderContainer) != null){
                jQuery("#pager_order", orderContainer).val(order);
            }

            orderColumn = jQuery(this).attr("id");
            if(jQuery("#pager_orderColumn", orderContainer) != null) {
                jQuery("#pager_orderColumn", orderContainer).val(orderColumn);
            }
            if(jQuery("#curPageHid", pageContainer) != null && jQuery("#curPageHid", pageContainer).val() != "0") {
                jQuery("#curPageHid", pageContainer).val("1");
            }
            orderSearch(pageContainerId, orderContainerId);
        });
    });
}

//setTableData
function setTableData(tblId, arrTblData, arrCols, arrColStyle, noHeader, arrRowClass, rowSet){
    var strTblData = "";
    var strFun;
    var strTemp;
    var strArg;
    var strRowFun;
    if(noHeader){
        strTblData = "";
    }else{
        jQuery("tr ~ tr", jQuery("#" + tblId)).each(function(){
            jQuery(this).replaceWith("");
        });
        jQuery("TBODY ~ TBODY", jQuery("#" + tblId)).each(function(){
            if(jQuery(this).find("tr").attr("id") != "trHeader"){
                jQuery(this).replaceWith("");
            }
        });
        strTblData = jQuery("#" + tblId).html();
    }

    for(var i = 0; arrTblData[i]; i++){
        var trData = "";

        if (arrRowClass == null || arrRowClass.length == 0){
            trData = trData + "<tr ";
        } else {
            trData = trData + "<tr class = '"+ arrRowClass[i%arrRowClass.length]+"' ";
        }

        if (rowSet != null && rowSet != ""){
            if(rowSet.indexOf("(") != -1){
                var rowLeftIndex = rowSet.indexOf("(");
                var rowNextIndex = rowSet.indexOf(",");
                var rowRightIndex = rowSet.indexOf(")");
                strRowFun = toTrim(rowSet.substring(0, rowLeftIndex + 1));
                strTemp = rowSet.substring(rowLeftIndex + 1, rowRightIndex);
                rowNextIndex = strTemp.indexOf(",");
                while(rowNextIndex != -1){
                    strArg = toTrim(strTemp.substring(0,rowNextIndex));
                    if(strArg == "_rowno"){
                        strRowFun = strRowFun + i + ",";
                    }else if(strArg == "_rowcount"){
                        strRowFun = strRowFun + arrTblData.length + ",";
                    }else{
                        temp=String(arrTblData[i][strArg]);
                        if(temp!=null){
                            temp=htmlTagReplace(temp.replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n"));
                        }
                        strRowFun = strRowFun + "\"" + temp + "\",";
                    }
                    strTemp = strTemp.substring(rowNextIndex + 1);
                    rowNextIndex = strTemp.indexOf(",");
                }
                if(toTrim(strTemp) == "_rowno"){
                    strRowFun = strRowFun + i + ")";
                }else if(toTrim(strTemp) == "_rowcount"){
                    strRowFun = strRowFun + arrTblData.length + ")";
                }else{
                    temp=String(arrTblData[i][toTrim(strTemp)]);
                    if(temp!=null){
                        temp=htmlTagReplace(temp.replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n"));
                    }
                    strRowFun = strRowFun + "\"" + temp + "\")";
                }
                trData = trData + eval(strRowFun);
            }else{
                trData = trData + rowSet;
            }
        }
        trData = trData + " >";

        for(var j=0; j < arrCols.length; j++){
            if( arrColStyle[j].indexOf("'") == -1 &&
                arrColStyle[j].indexOf("=") == -1){
                trData = trData + "<td style='" + arrColStyle[j] + "'>";
            }else{
                trData = trData + "<td " + arrColStyle[j] + " >";
            }
            if(arrCols[j].indexOf("(") != -1){
                var leftIndex = arrCols[j].indexOf("(");
                var nextIndex = arrCols[j].indexOf(",");
                var rightIndex = arrCols[j].indexOf(")");
                strFun = toTrim(arrCols[j].substring(0, leftIndex + 1));
                strTemp = arrCols[j].substring(leftIndex + 1, rightIndex);
                nextIndex = strTemp.indexOf(",");
                while(nextIndex != -1){
                    strArg = toTrim(strTemp.substring(0,nextIndex));
                    if(strArg == "_rowno"){
                        strFun = strFun + i + ",";
                    }else if(strArg == "_rowcount"){
                        strFun = strFun + arrTblData.length + ",";
                    }else{
                        var temp=String(arrTblData[i][strArg]);
                        if(temp!=null){
                            temp=htmlTagReplace(temp.replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n"));
                        }
                        strFun = strFun + "\"" + temp + "\",";
                    }
                    strTemp = strTemp.substring(nextIndex + 1);
                    nextIndex = strTemp.indexOf(",");
                }
                if(toTrim(strTemp) == "_rowno"){
                    strFun = strFun + i + ")";
                }else if(toTrim(strTemp) == "_rowcount"){
                    strFun = strFun + arrTblData.length + ")";
                }else{
                    temp=String(arrTblData[i][toTrim(strTemp)]);
                    if(temp!=null){
                        temp=htmlTagReplace(temp.replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n"));
                    }
                    strFun = strFun + "\"" + temp + "\")";
                }
                trData = trData + eval(strFun);
            }else{
                trData = trData + arrTblData[i][arrCols[j]];
            }
            trData = trData + "</td>";
        }
        
        trData = trData + "</tr>";
        
        strTblData = strTblData + trData;
    }

    setInnerHTML(tblId, strTblData);
}

//setSortable
function setSortable(arrFromList, arrToList, tagItems, createNode, arrArguments)
{
    if(tagItems == null || tagItems == ""){
        tagItems = "li";
    }
    if(typeof(arrFromList) != "object"){
        arrFromList = Array(arrFromList);
    }

    if(typeof(arrToList) != "object"){
        arrToList = Array(arrToList);
    }
    
    for(var i = 0; i < arrFromList.length; i++){
        var strList = {connectWith:[],items:tagItems};
        for(var j = 0; j < arrToList.length; j++){
            if(arrFromList[i] != arrToList[j]){
                strList.connectWith[strList.connectWith.length] = "#" + arrToList[j];
            }
        }
        jQuery("#" + arrFromList[i]).sortable(strList);
    }

    for(var j = 0; j < arrToList.length; j++){
        jQuery("#" + arrToList[j]).sortable({items:tagItems});
    }

    if(createNode != null){
        if(typeof(arrArguments) != "object"){
            arrArguments = Array(arrArguments);
        }

        for(var k = 0; k < arrToList.length; k++){
            jQuery("#" + arrToList[k]).bind("sortreceive",
                    function(event, ui) {
                    var arrValues = new Array();
                    for(var i=0; i < arrArguments.length; i++){
                        arrValues.push(ui.item.find("#" + arrArguments[i]).val());
                    }
                    ui.item.replaceWith(createNode(arrValues));
                });
        }
    }
}

function setTransferTable(arrFromList, arrToList, tagItems, createNode, arrArguments) {
    if(tagItems == null || tagItems == ""){
        tagItems = "li";
    }
    if(typeof(arrFromList) != "object"){
        arrFromList = Array(arrFromList);
    }

    if(typeof(arrToList) != "object"){
        arrToList = Array(arrToList);
    }
    
    for(var i = 0; i < arrFromList.length; i++){
        var strList = {connectWith:[],items:tagItems};
        for(var j = 0; j < arrToList.length; j++){
            if(arrFromList[i] != arrToList[j]){
                strList.connectWith[strList.connectWith.length] = "#" + arrToList[j];
            }
        }
        jQuery("#" + arrFromList[i]).find("img[id='imgDelete']").bind("click",function(){
            var li = jQuery(this).parent().parent().parent().parent().parent();
            var tr = jQuery(this).parent().parent();
            if(jQuery(tr).attr("flag") == "1"){
                return;
            }
            
            var css = jQuery(li).attr('class');
            var li_id = jQuery(li).attr('id');
            var arrValues = new Array();
            if(createNode != null){
                if(typeof(arrArguments) != "object"){
                    arrArguments = Array(arrArguments);
                }
                for(var i=0; i < arrArguments.length; i++){
                    arrValues.push(htmlTagReplace(jQuery("#" + li_id).find("#" + arrArguments[i]).val()));
                }
            }

            jQuery(tr).attr("flag", "1");
            for(var j = 0; j < arrToList.length; j++){
                objAppend(arrToList[j], createNode(arrValues));
            }
            liImageInit(arrToList);
            var tr_id = jQuery(tr).attr('id');
            jQuery(tr).attr("class","BClickmoveGrayoutOdd");

            
        });
    }
    liImageInit(arrToList);
}
function liImageInit(ulId){
    var length = jQuery("#" + ulId + " li").length;
    for(var i=0; i<length; i++){
        var objTd = jQuery("#" + ulId).find("li").eq(i).find("td").eq(2);
        if(i == 0){
            objTd.find("img").eq(0).attr("src", getskip_FirstUp());
        }else{
            objTd.find("img").eq(0).attr("src", getskip_up());
        }
        if(i == length-1){
            objTd.find("img").eq(1).attr("src", getskip_LastDown());
        }else{
            objTd.find("img").eq(1).attr("src", getskip_down());
        }
    }
}
function li_del(objId, fromUlId, toUlId){
    objReplaceWith(objId, "");
    var objToId = toUlId + objId.replace(fromUlId, "");
    if(jQuery("#" + objToId).attr("id")){
        var index = jQuery("#" + objToId).find("tr:first").attr("id");
        jQuery("#" + objToId).find("tr:first").attr("class","BClickmoveOdd");
    }
    jQuery("#" + objToId).find("tr:first").attr("flag", "0");
}
function li_up(liId, ulId){
//  jQuery("#" + ulId).find("img:first").attr("src",getskip_up());
  strUlHTML = jQuery("#" + ulId).html();
  jQuery("#" + ulId).children().each(function(){
      if(jQuery(this).attr("id") != liId){
          jQuery(this).replaceWith("");
      }
  });
  strLiHTML = jQuery("#" + ulId).html();
  jQuery("#" + ulId).html(strLiHTML + strUlHTML);
  jQuery("#" + ulId).find("#"+ liId).each(function(i){
//      if(i == 0){
//          jQuery("#" + ulId).find("img:first").attr("src",getskip_FirstUp());
//      } else {}
      if(i == 1){
          jQuery(this).replaceWith("");
      } else {}
  });
  li_order(ulId);
}

function li_down(liId, ulId){
  strUlHTML = jQuery("#" + ulId).html();
  jQuery("#" + ulId).children().each(function(){
      if(jQuery(this).attr("id") != liId){
          jQuery(this).replaceWith("");
      }
  });
  strLiHTML = jQuery("#" + ulId).html();
  jQuery("#" + ulId).html(strUlHTML + strLiHTML);
  jQuery("#" + ulId).find("#"+ liId).each(function(i){
      if(i == 0){
          jQuery(this).replaceWith("");
      }
  });
  li_order(ulId);
}

function li_order(ulId){
  var i = 1;
  jQuery("#" + ulId).find("span[id='liNo']").each(function(){
      jQuery(this).text(i++);
  });
  liImageInit(ulId);
}
function htmlTagReplace(str){
    var returnStr = str.replace(eval('/</g'),"&lt;").replace(eval('/>/g'),"&gt;").replace(eval('/"/g'),"&quot;");
    return returnStr;
}
function sortable(ulId, tagItems){
    jQuery("#" + ulId).sortable({items:tagItems});
}
function setSortableStopEvent(objId, stopFun, data){
    jQuery("#" + objId).bind("sortstop", function(event, ui) {stopFun(data, event, ui)});
}

//firefox event deal function start
function SearchEvent() 
{
    func=SearchEvent.caller; 
    while(func!=null) 
    { 
        var arg0=func.arguments[0]; 
        if(arg0) 
        {
            if( arg0.constructor==Event ||
                arg0.constructor==MouseEvent ||
                (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){
                return arg0;
            }
        } 
        func=func.caller; 
    } 
    return null; 
} 
//firefox event deal function end

//tree
function createNode(json){
    var nodeHtml = "";
    for(var i = 0; i < json.length; i++){
        nodeHtml += "<li id='" + json[i].id + "'";
        if(json[i].type) nodeHtml += " name='" + json[i].type + "'";
        if(json[i].open && json[i].open == "open") nodeHtml += " class='open'";
        nodeHtml += "><span";
        if(json[i].type) nodeHtml += " class='" + json[i].type + "'";
        nodeHtml += ">" + json[i].name + "</span>";
        if(json[i].children){
            nodeHtml += "<ul>";
            nodeHtml += createNode(json[i].children);
            nodeHtml += "</ul>";
            nodeHtml += "</li>";
        }else{
            nodeHtml += "</li>";
        }
    }
    
    return nodeHtml;
}

function initTree(divTree, json){
    var treeHtml;
    treeHtml  =  "<ul class=\"simpleTree\">";
    treeHtml += "<li class=\"root\" id=\"root\">";
    treeHtml += "<ul>";
    treeHtml += createNode(json);
    treeHtml += "</ul>";
    treeHtml += "</li>";
    treeHtml += "</ul>";

    jQuery('#' + divTree).html(treeHtml);
}

function getTreeByJsonString(node){
    var jsonString="";
    jsonString += "[";
    $('>ul>li',node).each(function(){
        if(this.id){
            jsonString += "{";
            jsonString += "\"id\":\"" + this.id + "\"";
            jsonString += ",\"name\":\"" + $('span:first',this).text() + "\"";
            if(this.name) jsonString += ",\"type\":\"" + this.name + "\"";
            if(this.className && this.className.indexOf("open")>-1) jsonString += ",\"open\":\"open\"";
            if($('>ul',this).size() > 0){
                jsonString += ",\"children\":" + getTreeByJsonString(this);
            }
            jsonString += "},";
        }
    });
    jsonString = jsonString.substring(0,jsonString.length-1);
    jsonString += "]";
    
    return jsonString;
}

function getTreeMaxSize(){
    var treeSize = 0;
    jQuery("#root").find("li").each(function(){
        if(jQuery(this).attr("id") && jQuery(this).parents("ul").size() > treeSize){
            treeSize = jQuery(this).parents("ul").size();
        }
    });
    if(treeSize > 0){
        return treeSize-1;
    }else{
        return 0;
    }
}
//tree

function closeWindow(){
    window.opener=null;
    window.open('','_self');
    window.close();
    //self.close();
}

function arrayToJson(array){
    var json="[";
    for(var i = 0; i < array.length; i++) {
//        temp=array[i].replace(/\\/g, "\\\\")

        if(navigator.userAgent.toLowerCase().indexOf("ie") != -1) {  //ie
            temp=array[i].replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
        } else {
            temp=array[i].replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
        }
//        temp=array[i].replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
        json +='"'+temp.replace(/"/g, "\\\"")+'"';
        if(array.length-1!=i){
           json+=",";
        }
    }
    json+="]";
    return json;
}

String.prototype.format = function()
{
    var args = arguments;
    return this.replace(/\{(\d+)\}/g,              
        function(m,i){
            return args[i];
        });
}

String.format = function() {
    if( arguments.length == 0 )
        return null; 

    var str = arguments[0]; 
    for(var i=1;i<arguments.length;i++) {
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
} 

function showDiv(divId){
    jQuery(document.createElement('div'))
    .attr('id', 'divShowBg')
    .css({ 'position': 'absolute', 'top': '0', 'left': '0', 'z-index': '9999', 
        'filter': 'alpha(opacity=70)', 'backgroundColor': '#999', 'opacity': '0.5', 
        'width': '100%', 
        'height': document.documentElement.scrollHeight + 'px' })
    .appendTo('body'); 

    var divHeight = jQuery('#' + divId).height();
    var divWidth = jQuery('#' + divId).width();
    jQuery('#' + divId).css({ 'position': 'absolute', 
        'top': (jQuery(window).height() - divHeight) / 2 + jQuery(window).scrollTop() + 'px', 
        'left': (jQuery(window).width() - divWidth) / 2 + jQuery(window).scrollLeft() + 'px', 
        'border': '1px solid #cef', 'zIndex': '10000', 'backgroundColor': '#fff',
        'height': divHeight, 'width':divWidth,
        'overflow': 'hidden' })
    .show();

    window.onscroll = function(){
        jQuery('#' + divId)
        .css({'position': 'absolute', 
            'top': (jQuery(window).height() - divHeight) / 2 + jQuery(window).scrollTop() + 'px', 
            'left': (jQuery(window).width() - divWidth) / 2 + jQuery(window).scrollLeft() + 'px', 
            'border': '1px solid #cef', 'zIndex': '10000', 'backgroundColor': '#fff', 
            'height': divHeight, 'width':divWidth,
            'overflow': 'hidden' });
    };
    

}

function closeDiv(divId){
    jQuery('#divShowBg').remove();
    jQuery('#' + divId).hide();
}

function fnBreakWordAll(o){
    var o = o || {},
      iWord = o.word || 13,
      iRe = o.re || '[a-zA-Z0-9]',
      bAll = o.all || false,
      sClassName = o.className || 'word-break-all',
      aEls = o.els || (function(){
        var aEls = [],
          aAllEls = document.getElementsByTagName('*'),
          re = new RegExp('(?:^|\\s+)' + sClassName + '(?:\\s+|$)');
        for(var i =0,iLen = aAllEls.length; i < iLen ; ++i){
          if(re.test(aAllEls[i].className)){
            aEls[aEls.length] = aAllEls[i];
          }
        }
        return aEls;
      })() || [],
      fnBreakWord = function(oEl){
        if(!oEl || oEl.nodeType !== 1){
          return false;
        }else if(oEl.currentStyle && typeof oEl.currentStyle.wordWrap==='string'){
          breakWord = function(oEl){
            oEl.runtimeStyle.wordWrap = 'break-word';
            return true;
          }
          return breakWord(oEl);
        }else if(document.createTreeWalker){
          var trim = function  (str) {
            str = str.replace(/^\s\s*/, '');
            var ws = /\s/,
            i = str.length;
            while (ws.test(str.charAt(--i)));
            return str.slice(0, i + 1);
          }
          breakWord = function(oEl){
            var dWalker=document.createTreeWalker(oEl,NodeFilter.SHOW_TEXT,null,false);
            var node,s,c = String.fromCharCode('8203'),
              re = new RegExp('('+ iRe +'{0,' + iWord + '})');
            while (dWalker.nextNode()){
              node = dWalker.currentNode;
              s = trim(node.nodeValue).split(re).join(c);
              node.nodeValue = s;
            }
            return true;
          }
          return breakWord(oEl);
        }
      };
    for(var i=0,n=aEls.length; i<n; ++i){
      var sUa = navigator.userAgent,
        sTn = aEls[i].tagName.toLowerCase() ;
      if((/Opera/).test(sUa) || (/Firefox/).test(sUa) || ((/KHTML/).test(sUa) &&
      (sTn === 'td' || sTn === 'th')) || bAll){
        fnBreakWord(aEls[i]);
      }
    }
}

function initSelectable(objId, selectedCallBack, width){
    jQuery(function($){
          obj = $("#" + objId).jQselectable({
            set         : "fadeIn",
            setDuration : "fast",
            opacity     : .9,
            width       : width,
            callback    : selectedCallBack
        });
    });
    return obj;
}

var arrChildrenWindows = new Array();
function windowOpenOne(strModuleUrl, strGroupName) {
    for (var key in arrChildrenWindows) {
        if (strGroupName == key ) {
            if (arrChildrenWindows[key].closed) {
                arrChildrenWindows[key] = window.open(getHost() + strModuleUrl, strGroupName);
            } else {}
            return;
        } else {}
    }

    arrChildrenWindows[strGroupName] = window.open(getHost()+ strModuleUrl, strGroupName);
}
function logout() {
    document.getElementById("logoutForm").action = getHost() + "common/logout/logout";
    document.getElementById("logoutForm").submit();
}

function getImagePath(imageInfo,sizeFlag){
    var ext;
    var imageId;
    var imageName;
    var tempImageName;
    var imageFullPath;
    var imagePath;
    var arrImageInfo;
    var arrImageNameInfo;
    var defaultImagePath = "";
    var arrImageInfo = new Array();

    if (imageInfo != null) {
        arrImageInfo    = imageInfo.split("|");
        if (arrImageInfo[0] == null) {
            imageId = "";
        } else {
            imageId = arrImageInfo[0];
        }
        if (arrImageInfo[1] == null) {
            imageFullPath = "";
        } else {
            imageFullPath = arrImageInfo[1];
        }
        if (arrImageInfo[2] == null) {
            imageName = "";
        } else {
            tempImageName = arrImageInfo[2];
            arrImageNameInfo = tempImageName.split(".");
            ext = arrImageNameInfo[1];
            if (ext != null) {
                ext = ext.toLowerCase();
                if (ext == "png") {
                    if (sizeFlag != 0) {
                        imageName = arrImageNameInfo[0] + ".gif";
                    } else {
                        imageName = arrImageNameInfo[0] + ".png";
                    }
                } else {
                    imageName = arrImageNameInfo[0] + "." + ext;
                }
                imageName = encodeURIComponent(imageName);
            } else {
                imageName = "";
            }
        }
        if (imageId != "" && imageFullPath != "" && imageName != "") {
            if (sizeFlag == 0) {
                imagePath = imageFullPath + "/" + imageId + "/" + imageName;
            } else if (sizeFlag == 1) {
                imagePath = imageFullPath + "/" + imageId  + "/thumbnail/" + imageName;
            } else if (sizeFlag == 2) {
                imagePath = imageFullPath + "/" + imageId  + "/item_S/" + imageName;
            } else if (sizeFlag == 3) {
                imagePath = imageFullPath + "/" + imageId  + "/item_M/" + imageName;
            } else if (sizeFlag == 4) {
                imagePath = imageFullPath + "/" + imageId  + "/item_L/" + imageName;
            } else if (sizeFlag == 5) {
                imagePath = imageFullPath + "/" + imageId  + "/item_XL/" + imageName;
            } else if (sizeFlag == 6) {
                imagePath = imageFullPath + "/" + imageId  + "/item_XS/" + imageName;
            } else if (sizeFlag == 7) {
                imagePath = imageFullPath + "/" + imageId  + "/item_XXL/" + imageName;
            } else {
                imagePath = defaultImagePath;
            }
        } else {
            imagePath = defaultImagePath;
        }
    } else {
        imagePath = defaultImagePath;
    }
    arrImageInfo[0] = imagePath;
    arrImageInfo[1] = imageId;
    return arrImageInfo;
}

function setSubmitDisable(objId){
    if (objId != "") {
        var obj=document.getElementById(objId);
        obj.disabled = "disabled";
    }
    createWaitDiv();
}

function setSubmitEnable(objId){
    if (objId != "") {
        var obj=document.getElementById(objId);
        obj.disabled = "";
    }
    if(jQuery('#divPause') != null){
        document.getElementById('divPause').style.display='none';
        jQuery('#divPause').remove();
    }
}

function createWaitDiv(){
     jQuery(document.createElement('div')).attr('id', 'divPause')
     .css({ 'position': 'absolute', 'top': '0', 'left': '0', 'z-index': '9999', 
        'width': "100%", 
        'height': document.documentElement.scrollHeight + 'px',
        'text-align': 'center',
        'font': 'bold 24px arial',
        'background-repeat': 'no-repeat',
        'background-position': 'center',
        'background-attachment': 'fixed'
    })
    .appendTo('body');
    setTimeout("displayWaitDiv()", 500);
}

function displayWaitDiv(){
    if(jQuery('#divPause') != null){
        jQuery('#divPause').css({'background-image':'url(' + getAjaxWaitImage() + ')'});
    }
}       
function toLowerCase(objId){
    var value = jQuery("#" + objId).val();
    jQuery("#" + objId).val(value.toLowerCase());
}
function mailConvert(objId){
    toLowerCase(objId);
}
function domainConvert(objId){
    toLowerCase(objId);
}
function autoSetValue(objid) {
    document.getElementById(objid).setAttribute('value',getValue(objid));
}

function checkAll(e, strName) {
    var arrAllChk = document.getElementsByName(strName);
    var intLength = arrAllChk.length;
    for (var i = 0;i < intLength; i++) {
        arrAllChk[i].checked = e.checked;
    }
}

function checkBack(e, strId) {
    var intCheckCount = 0;
    var objList = document.getElementsByName(e.name);
    var intLength = objList.length;
    for (var i=0; i < intLength; i++) {
        if (objList[i].checked == true) {
            intCheckCount++;
        }
    }
    if (intCheckCount == intLength) {
        setChecked(strId, true);
    } else {
        setChecked(strId, false);
    }
}